﻿
@{
    ViewBag.Title = "用户管理";
    Layout = "~/Views/Shared/_ManagerLayoutPage.cshtml";
}

<div class="row">
    <div class="col-md-12">
        <div class="card">
            <div class="card-body" style="padding: 1.75rem 2.8125rem;">
                <div class="row">
                    <div class="col-md-12 clearfix" style="padding-left:0px;">
                        <p style="font-size:15px;font-weight:bold;">用户管理</p>
                        <div class="my-4 row">
                            <div class="col-sm-3">
                                <div class="input-group">
                                    <input type="text" id="para" name="input1-group2" class="form-control" placeholder="请输入手机号或姓名">
                                    <span class="input-group-btn">
                                        <button type="button" class="btn btn-primary" onclick="ShowModuleContent(this,1)"><i class="fa fa-search"></i></button>

                                        <a class="btn btn-success" style="color:white; display: none;" target="_blank" href="@RS.Environment.ConfigurationHelper.GetAppSettings("VirtualUrl")/UserManager/UserEdit">新增用户</a>
                                    </span>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-md-12" style="padding-left: 0;">
                        <div class="card" style="border-color:#f6f6f6;">
                            <div class="card-body" style="padding: 0;">
                                <div class="table-responsive">
                                    <table class="table mb-0">
                                        <thead>
                                            <tr>
                                                <th>系统编号</th>
                                                <th>姓名</th>
                                                <th>工号</th>
                                                <th>域账号</th>
                                                <th style="text-align:center;">注册时间</th>

                                                <th style="text-align:center;">状态</th>
                                                <th style="text-align:center;">操作</th>
                                            </tr>
                                        </thead>
                                        <tbody id="basic_content">

                                         </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>


                <div class="row">
                    <div class="col-md-12">
                        <div class="pageindex" id="page_index">
                            <a id="pre_page" style="cursor:pointer;">上一页</a>
                            <span id="current_num">1</span>&nbsp;/&nbsp;<span id="total_num">1</span>
                            <a id="next_page" style="cursor:pointer;">下一页</a>
                        </div>
                    </div>

                </div>

            </div>
        </div>
    </div>

</div>

@section ChildPageScript
    {


    <script>

        var id = "";

        var current_num;

        var total_num;

        $("#loading").hide();

        $(function () {

            ShowModuleContent(null,1);

        });
        $("#pre_page").click(function () {
            if (total_num != null) {
                var i = parseInt(current_num);
                if (i == 1)
                {
                }
                else if (i > 1)
                {
                    ShowModuleContent($("#pre_page"),i-1);
                }
            }
        });
        $("#next_page").click(function () {
            if (total_num != null) {
                var j = parseInt(total_num);
                var i = parseInt(current_num);
                if (j == i)
                {
                }
                else if (j > i)
                {
                    ShowModuleContent($("#next_page"),i+1);
                }
            }
        });

        function SetPageNum() {
            $("#total_num").html(total_num);
            $("#current_num").html(current_num);
            if (total_num > 1) {
                $("#page_index").show();
            }
        }

       function ShowModuleContent(obj, pagenum)
       {
            if (obj != null)
            {
                $(obj).attr("disabled", "disabled");
            }

            $("#page_index").hide();
           var para = $("#para").val();
            $.ajax({

                url: "@RS.Environment.ConfigurationHelper.GetAppSettings("VirtualUrl")" + "@Url.Action("GetUserList", "UserManager")",
                dataType: "json",
                data: { "pagenum": pagenum, "para": para,"pagesize":10},
                type: "get",
                success: function (data) {
                    console.log(data);

                    if (data.IsError) {
                        Notic('error',data.Message);
                    }
                    else {
                        var html = "";
                        var index = 0;
                        $(data.Result.content).each(function ()
                        {
                            html += "<tr>";
                            html +="<td>"+this["UniqueId"]+"</td>";
                            html += "<td>" + this["Name"] + "</td>";
                            html += "<td>" + (this["JobNumber"]==null?"":this["JobNumber"]) + "</td>";
                            html += "<td>" + (this["LoginName"] == null ? "" : this["LoginName"]) + "</td>";
                            html += "<td style='text-align:center;'>" + this["CreateTime"].replace("T", " ") + "</td>";
                            html += "<td>" + (this["Status"] == "1" ? "正常" : "<span style='color:red;'>停用</span>") + "</td>";
                            html += '<td style="text-align:center;">';

                            if (this["Status"] == "1")
                            {
                                html += '<a class="btn btn-outline-success  btn-sm" href="javascript:void(0)" onclick=ChangeStatus(this,"'+this["Id"]+'",0) >禁用</a>';
                            }
                            else
                            {
                                html += '<a class="btn btn-outline-success  btn-sm" href="javascript:void(0)" onclick=ChangeStatus(this,"'+this["Id"]+'",1) >恢复</a>';
                            }
                            html += ' <a class="btn btn-outline-primary  btn-sm" target="_blank" href="@RS.Environment.ConfigurationHelper.GetAppSettings("VirtualUrl")/UserManager/UserDetail?id=' + this["Id"] + '">查看</a>';
                            html += " <a class='btn btn-outline-warning btn-sm' target='_blank' href='@RS.Environment.ConfigurationHelper.GetAppSettings("VirtualUrl")/UserManager/UserEdit?id=" + this["Id"] + "'>编辑</a>";

                            html += '</td>';
                            html += "</tr>";
                        });
                        $("#basic_content").html(html);

                        total_num = data.Result.total_num;

                        current_num = pagenum;
                        SetPageNum();
                    }


                },
                fail: function (data) {


                },
                complete: function (data) {
                    //$("#loading").hide();
                    $(obj).removeAttr("disabled");
                }
            });
        }
        $("#basic_search").click(function ()
        {

            ShowModuleContent(this, current_num);

        });
    </script>

    <script>

        function ChangeStatus(obj,id,status)
        {

            $(obj).attr("disabled","disabled");
            $.ajax({
                url: "@RS.Environment.ConfigurationHelper.GetAppSettings("VirtualUrl")" + "/UserManager/UpdateUser",
                data: { "status": status,"id":id},
                dataType: "json",
                type:"post",
                success: function (data)
                {
                    if (data.IsError)
                    {


                        Notic('error', data.Message);

                    }
                    else
                    {
                        ShowModuleContent(this, current_num);

                    }
                    $(obj).removeAttr("disabled");

                }
            });





        }


    </script>
}

